//
//  MainViewController.swift
//  CSSinaMicroBlog_Test
//
//  Created by 姚彦兆 on 15/11/11.
//  Copyright © 2015年 姚彦兆. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //取得自定义的TabBar
    var customTabBar : CSYTabBar {
    
        let csTabBar = CSYTabBar()
        
        return csTabBar
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //将系统的TabBar替换成自定义的Tabbar
        setValue(customTabBar, forKey: "tabBar")
        
        
        
        addChildviewControllers()
        
    }
    
    private func addChildviewControllers(){
    
        //添加子控制器
        addChildViewController(HomeTableViewController(), controllerTitle: "首页", controllerImage: "tabbar_home")
    
        addChildViewController(MessageTableViewController(), controllerTitle: "消息", controllerImage: "tabbar_message_center")
        
        addChildViewController(DiscoverTableViewController(), controllerTitle: "发现", controllerImage: "tabbar_discover")
        
        addChildViewController(ProfileTableViewController(), controllerTitle: "我", controllerImage: "tabbar_profile")
        
    }
    
    func addChildViewController(childController: UIViewController , controllerTitle : String , controllerImage : String) {
        
        //将子控制器封装在导航控制器中并且添加
        
        let mainNav = UINavigationController(rootViewController: childController)
        
        childController.title = controllerTitle
        
        childController.tabBarItem.image = UIImage(named: controllerImage)
        
        addChildViewController(mainNav)
        
    }
    
    
    

}
